package com.luoc;

import java.util.Hashtable;

/**
 * @Author: luoc
 * @Date: 2019/9/24 8:42
 */
public abstract class Igochessman {

    public abstract String getColor();
    public void disPlay(){
        System.out.println("颜色:"+this.getColor());
    }
}

class blackIgochessman extends  Igochessman{

    @Override
    public String getColor() {
        return "black";
    }
}


class redIgoChessman extends  Igochessman{

    @Override
    public String getColor() {
        return "red";
    }
}

class IgochessManFactory {
    //　创建工厂类
    private static IgochessManFactory instance = new IgochessManFactory();
    // 充当享元池
    public static  Hashtable<String,Object> hashtable;

    private IgochessManFactory(){
        hashtable = new Hashtable();
        Igochessman red,black;
        red = new redIgoChessman();
        black = new blackIgochessman();
        hashtable.put("red",red);
        hashtable.put("black",black);
    }

    public  static  IgochessManFactory getInstance(){
        return instance;
    }


    public  static   Igochessman getIgochessman(String color){
         return (Igochessman) hashtable.get(color);
    }



}